import request from "@/request";

// 参数接口
export interface UpdateBorrowParams {
    id?: number;
    serial?: string;
    booknoId?: number;
    booknoName?: string;
    userId?: number;
    userName?: string;
    type?: number;
    createBy?: string;
    createTime?: string;
    updateBy?: string;
    updateTime?: string;
    undock?: number;
    unlucky?: number;
    remark?: string;
}

// 响应接口
export interface UpdateBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 修改编号
 * @param {object} params $!{table.comment}
 * @param {number} params.id 编号
 * @param {string} params.serial 流水编号
 * @param {number} params.booknoId 书本条码
 * @param {string} params.booknoName 书本名称
 * @param {number} params.userId 用户编号
 * @param {string} params.userName 流水用户
 * @param {number} params.type 借阅类别（0-借书 1-还书）
 * @param {string} params.createBy 创建者
 * @param {string} params.createTime 创建时间
 * @param {string} params.updateBy 更新者
 * @param {string} params.updateTime 更新时间
 * @param {number} params.undock 伪删除（0-已 1-未）
 * @param {number} params.unlucky 状态（0-禁用 1-正常）
 * @param {string} params.remark 备注
 * @returns
 */
export function updateBorrow(params: UpdateBorrowParams): Promise<UpdateBorrowRes> {
    return request.post(`/borrowEntity/update`, params);
}

// 响应接口
export interface RecoverListBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 恢复列表
 * @returns
 */
export function recoverListBorrow(): Promise<RecoverListBorrowRes> {
    return request.post(`/borrowEntity/recoverList`);
}

// 响应接口
export interface RecoverBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 恢复数据
 * @param {string} param
 * @returns
 */
export function recoverBorrow(param: string): Promise<RecoverBorrowRes> {
    return request.post(`/borrowEntity/recover/${param}`);
}

// 响应接口
export interface ListPageBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 列表分页
 * @param {string} page
 * @param {string} pageSize
 * @returns
 */
export function listPageBorrow(page: number, pageSize: number): Promise<ListPageBorrowRes> {
    return request.post(`/borrowEntity/listPageBorrow?page=${page}&pageSize=${pageSize}`);
}

// 参数接口
export interface InsertBorrowParams {
    id?: number;
    serial?: string;
    booknoId?: number;
    booknoName?: string;
    userId?: number;
    userName?: string;
    type?: number;
    createBy?: string;
    createTime?: string;
    updateBy?: string;
    updateTime?: string;
    undock?: number;
    unlucky?: number;
    remark?: string;
}

// 响应接口
export interface InsertBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 保存数据
 * @param {object} params $!{table.comment}
 * @param {number} params.id 编号
 * @param {string} params.serial 流水编号
 * @param {number} params.booknoId 书本条码
 * @param {string} params.booknoName 书本名称
 * @param {number} params.userId 用户编号
 * @param {string} params.userName 流水用户
 * @param {number} params.type 借阅类别（0-借书 1-还书）
 * @param {string} params.createBy 创建者
 * @param {string} params.createTime 创建时间
 * @param {string} params.updateBy 更新者
 * @param {string} params.updateTime 更新时间
 * @param {number} params.undock 伪删除（0-已 1-未）
 * @param {number} params.unlucky 状态（0-禁用 1-正常）
 * @param {string} params.remark 备注
 * @returns
 */
export function insertBorrow(params: InsertBorrowParams): Promise<InsertBorrowRes> {
    return request.post(`/borrowEntity/insert`, params);
}

// 响应接口
export interface ImportExcelBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 导入数据
 * @param {string} file
 * @returns
 */
export function importExcelBorrow(file: object): Promise<ImportExcelBorrowRes> {
    return request.post(`/borrowEntity/importExcel`, file);
}

// 响应接口
export interface FindByNameBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 查询名称
 * @param {string} param
 * @returns
 */
export function findByNameBorrow(param: string): Promise<FindByNameBorrowRes> {
    return request.post(`/borrowEntity/findByNameBorrow/${param}`);
}

// 响应接口
export interface FindByIDBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 查询编号
 * @param {string} param
 * @returns
 */
export function findByIDBorrow(param: string): Promise<FindByIDBorrowRes> {
    return request.post(`/borrowEntity/findByIDBorrow/${param}`);
}

// 参数接口
export interface FindBorrowParams {
    id?: number;
    serial?: string;
    booknoId?: number;
    booknoName?: string;
    userId?: number;
    userName?: string;
    type?: number;
    createBy?: string;
    createTime?: string;
    updateBy?: string;
    updateTime?: string;
    undock?: number;
    unlucky?: number;
    remark?: string;
}

// 响应接口
export interface FindBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 条件查询
 * @param {object} params $!{table.comment}
 * @param {number} params.id 编号
 * @param {string} params.serial 流水编号
 * @param {number} params.booknoId 书本条码
 * @param {string} params.booknoName 书本名称
 * @param {number} params.userId 用户编号
 * @param {string} params.userName 流水用户
 * @param {number} params.type 借阅类别（0-借书 1-还书）
 * @param {string} params.createBy 创建者
 * @param {string} params.createTime 创建时间
 * @param {string} params.updateBy 更新者
 * @param {string} params.updateTime 更新时间
 * @param {number} params.undock 伪删除（0-已 1-未）
 * @param {number} params.unlucky 状态（0-禁用 1-正常）
 * @param {string} params.remark 备注
 * @returns
 */
export function findBorrow(params: FindBorrowParams): Promise<FindBorrowRes> {
    return request.post(`/borrowEntity/findBorrow`, params);
}

// 响应接口
export interface ExportExcelBorrowRes {
}

/**
 * 导出数据
 * @returns
 */
export function exportExcelBorrow(): Promise<ExportExcelBorrowRes> {
    return request.post(`/borrowEntity/exportExcel`, {}, {
        responseType: "blob"
    });
}

// 响应接口
export interface DeleteTempBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 暂时删除
 * @param {string} param
 * @returns
 */
export function deleteTempBorrow(param: string): Promise<DeleteTempBorrowRes> {
    return request.post(`/borrowEntity/deleteTemp/${param}`);
}

// 响应接口
export interface DeleteBorrowRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 永久删除
 * @param {string} param
 * @returns
 */
export function deleteBorrow(param: string): Promise<DeleteBorrowRes> {
    return request.post(`/borrowEntity/delete/${param}`);
}

// 响应接口
export interface BorrowBooknoRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 借阅还书
 * @param {string} bookno_code
 * @param {string} type
 * @returns
 */
export function borrowBookno(bookno_code: string, type: number): Promise<BorrowBooknoRes> {
    return request.post(`/borrowEntity/borrow?bookno_code=${bookno_code}&type=${type}`);
}


// 响应接口
export interface FindBorrowUserRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 用户借阅
 * @returns
 */
export function findBorrowUser(): Promise<FindBorrowUserRes> {
    return request.post(`/borrowEntity/findBorrowUser`);
}

// 响应接口
export interface FindBorrowEchartsRes {
    message: string;
    success: boolean;
    code: number;
    data: Record<string, unknown>;
}

/**
 * 借阅图表
 * @param {string} isCollepse
 * @returns
 */
export function findBorrowEcharts(isCollepse: boolean): Promise<FindBorrowEchartsRes> {
    return request.post(`/borrowEntity/findBorrowEcharts?isCollepse=${isCollepse}`);
}
